<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>"> 
    <title>选择住院费用界面</title>  
    <link rel="stylesheet" href="<%=path %>/plugins/layui/css/layui.css" media="all">
  </head>

  <script src="<%=path %>/plugins/layui/layui.js"></script>
  
<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
	  <legend>请君慎重选择</legend>
	</fieldset>	
	<div class="layui-row">
	    <div class="layui-col-md12">
	      <div class="layui-row grid-demo">
	        <div class="layui-col-md5">
	          <div class="grid-demo grid-demo-bg1"><span class="layui-badge-dot layui-bg-orange"></span></div>
	        </div>
	        
	        <div class="layui-col-md7">
	          <div class="grid-demo grid-demo-bg2">
					<div  class="layui-inline layui-icon layui-icon layui-icon-search" 
				  		style="font-size: 20px; color: #2B2B2B;font-weight:bold">综合搜索：
				  	</div>
				  	<div class="layui-inline">
				  		<input type="hidden" name="unitId" id="unitId" />
				  		<input oninput="OnInput (event)" onpropertychange="OnPropChanged (event)" value="" class="layui-input"
							id="unitAbbreviationName" autocomplete="off" name="unitAbbreviationName" placeholder="请输入药品名称" />
				  	</div>
			  </div>
	        </div>
	      </div>
	    </div>
	 </div>
	 
	<div class="layui-row">
	    <div class="layui-col-md12">
	      <div class="layui-row grid-demo">
	        <div class="layui-col-md2">
	          <div class="grid-demo grid-demo-bg1"><span class="layui-badge-dot layui-bg-orange"></span></div>
	        </div>
	        
	        <div class="layui-col-md9">
	          <div class="grid-demo grid-demo-bg2">
					<table id="select" lay-filter="medList"></table>	
			  </div>
	        </div>
	      </div>
	    </div>
	 </div>
</body>

<script>
layui.use(['table','form', 'layedit', 'laydate', 'jquery'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,$ = layui.jquery
  ,table = layui.table;



  //信息提示弹出层
  function message(data){
      layer.open({
        content: '<div style="padding: 20px 100px;">'+ data +'</div>'
        ,btn: '朕知道啦'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
      });
  }

  table.render({
    elem: '#select'
    ,url:'<%=path%>/biz/Standard_getAll.action'
    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
    ,cols: [[
       {field:'standName', title: '治疗名称', align: 'center', sort: true}
      ,{field:'standPrice', id: 'medFuntion', title: '费用价格', align: 'center', sort: true}
      ,{field:'count', title: '数量', align: 'center', sort: true, templet: '#count'}
      ,{field:'operator', title: '操作', align: 'center', templet: '#switchTpll', unresize: true}
    ]]
  });
  
  
  //监听选取药品操作
  form.on('checkbox(selected)', function(obj){
    //layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
    //根据药品编号获取药品数量
    var count = $("#"+this.value+"").val();
    //如果为抓取状态则将不可编辑数量输入栏
    if(obj.elem.checked){
    	$("#"+this.value+"").addClass("layui-disabled");
    }else{
    	$("#"+this.value+"").removeClass("layui-disabled")
    }
    //传入药箱操作
    standList(this.name, this.value, obj.elem.checked, count);
  });

  //构建选取药品集合medList
  function standList(name, value, checked, count){
  	//初始化全局变量药箱集合
  	if(standLists == null){
  	  standLists = new Array();
  	}
    //构造药品对象
  	var med = {
  		"standName": name,
  		"standId": value,
  		"count": count
  	}
  	//未抓取状态则删除
  	if(checked == false){
  		//根据值来删除数组中的对象
  		standLists.splice($.inArray(med,standList), 1);
  	}else{
  		//抓取状态则加入数组
  	  	standLists.push(med);
  	}
  }
  	
  
  $('#layerDemo .layui-btn').on('click', function(){
    var othis = $(this), method = othis.data('method');
    active[method] ? active[method].call(this, othis) : '';
  });
  
});
	
  var standLists = null;//全局变量
  //返回构建好的药箱
  function messages(){
  	 return standLists;
  }
</script>


<!-- d为对应行数据~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<script type="text/html" id="switchTpll">
  <input type="checkbox" name="{{d.standName}}" value="{{d.standId}}" title="抓取" lay-filter="selected" {{ d.id == 10006 ? 'checked' : '' }}>
</script>
<!-- input的id根据药品编号来设置，以便获取 -->
<script type="text/html" id="count">
	<input id={{d.standId}} value="1" class="layui-input" type="text" lay-filter="counted"
		onkeyup="value=value.replace(/[^\d]/g,'') " ng-pattern="/[^a-zA-Z]">
</script>
</html>